<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑器 - ECharts配置管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css">
    <link rel="stylesheet" href="css/styles.css">
    <!-- Monaco Editor -->
    <link rel="stylesheet" data-name="vs/editor/editor.main" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs/editor/editor.main.min.css">
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="index.html">ECharts配置管理系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link active" href="editor.html">
                            <i class="bi bi-plus-lg"></i> 新建配置
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="configs.html">
                            <i class="bi bi-list"></i> 配置列表
                        </a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle text-white" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <span id="username">用户</span>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
                            <li><a class="dropdown-item" href="#" id="logoutBtn">退出登录</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- 主要内容 -->
    <div class="container mt-4">
        <div class="row">
            <div class="col-md-6">
                <div class="card mb-4">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <h5 class="mb-0">配置编辑器</h5>
                        <div>
                            <button id="loadTemplateBtn" class="btn btn-outline-secondary btn-sm">
                                <i class="bi bi-file-earmark-text"></i> 加载模板
                            </button>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label for="configName" class="form-label">配置名称</label>
                            <input type="text" class="form-control" id="configName" placeholder="输入配置名称">
                        </div>
                        <div class="mb-3">
                            <label for="configDescription" class="form-label">配置描述</label>
                            <input type="text" class="form-control" id="configDescription" placeholder="输入配置描述">
                        </div>
                        <div class="mb-3">
                            <label for="editor-container" class="form-label">ECharts配置 (JSON)</label>
                            <div id="editor-container" style="height: 400px; border: 1px solid #ddd;"></div>
                        </div>
                        <div id="editorError" class="alert alert-danger d-none"></div>
                    </div>
                </div>
            </div>
            <div class="col-md-6"></div>
                <div class="card mb-4">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <h5 class="mb-0">图表预览</h5>
                        <div>
                            <button id="saveBtn" class="btn btn-primary btn-sm">
                                <i class="bi bi-save"></i> 保存配置
                            </button>
                            <button id="resetBtn" class="btn btn-secondary btn-sm ms-2">
                                <i class="bi bi-arrow-counterclockwise"></i> 重置
                            </button>
                        </div>
                    </div>
                    <div class="card-body">
                        <div id="chartContainer" style="height: 500px;"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 模板选择模态框 -->
    <div class="modal fade" id="templateModal" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">选择图表模板</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body"></div>
                    <div class="row g-3" id="templateContainer">
                        <!-- 模板将通过JavaScript动态加载 -->
                    </div>div>
                </div>
            </div>
        </div>
    </div>

    <!-- 保存成功模态框 -->
    <div class="modal fade" id="saveSuccessModal" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">保存成功</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <p>配置已成功保存！</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">继续编辑</button>
                    <a href="configs.html" class="btn btn-primary">查看所有配置</a>
                </div>
            </div>
        </div>
    </div>

    <!-- 脚本 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.1/dist/echarts.min.js"></script>
    
    <!-- Monaco Editor -->
    <script>var require = { paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs' } };</script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs/loader.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs/editor/editor.main.nls.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs/editor/editor.main.js"></script>
    
    <!-- 认证和编辑器脚本 -->
    <script src="js/auth.js"></script>
    <script src="js/editor.js"></script>